<script type="text/javascript">
var companies = <?php echo Zend_Json::encode($this->key_companies);?>;
$(document).ready(function(){
	$( "#inbound_company_code" ).blur(function(){
		if( companies[$(this).val()] == null ){
			$(this).val('');
		}
	});	
	$( "#product_group_code" ).change(function(){
		var tmp=$(this);
		$.ajax({
		   type: "POST",
		   url: "<?php echo $this->url(array("controller"=>"inbound-detail","action"=>"ajax-load-product","module"=>"inbound"),null,true)?>",
		   data: {"product_product_group_code":tmp.val(),"product_code":$('#inbound_detail_product_code').val()},
		   success: function(html){
		      $('#inbound_detail_product_code').html(html);
		   }
		 });
	});	
	$("#product_group_code").trigger('change');
});
</script>

<!-- thanh toolbar -->
<?php $act = (string)$this->inbound_type == '1' ? 'insert-out' : 'insert-in' ;?>
<?php $this->placeholder('toolbar')->captureStart();?>
<?php echo $this->partial('index/toolbar/excel.phtml', 'admin') ?>
<?php echo $this->partial('index/toolbar/excel-all.phtml', 'admin') ?>
<?php $this->placeholder('toolbar')->captureEnd();?>
<!-- / -->

<!-- submenu -->
<?php $this->submenu=array(
"Nguyên vật liệu"=>$this->url(array("inbound_warehouse_group_code"=>"NVL")),
"Thành phẩm"=>$this->url(array("inbound_warehouse_group_code"=>"TP")),
"Bao bì"=>$this->url(array("inbound_warehouse_group_code"=>"BB")),
);?>
<!-- / -->

<form id='adminForm' name='adminForm' method='post' action=''>
<dl class="zend_form">

	<!-- phần tìm kiếm -->	
	<div class='formSearh'>
	<fieldset>
		<legend>Thông tin tìm kiếm</legend>
		<?php echo $this->form->adminAction;?>
		<?php echo $this->form->inbound_create_time_a;?>
		<?php echo $this->form->inbound_create_time_b;?>	
		<?php echo $this->form->product_group_code;?>
		<?php echo $this->form->inbound_detail_product_code;?>
	</fieldset>
	</div>	
	<!-- / -->
	
	<!-- danh sách hiển thị -->
	<div class='clr'> </div>
	<div class='scroll'>
	<fieldset>
		<legend>BÁO CÁO CHI TIẾT NHẬP XUẤT TỒN</legend>
		<table class='adminlist'>
			<thead>			
				<tr>
					<th rowspan='2' width="50px">STT</th>
					<th rowspan='2'>Mã thành phẩm</th>
					<th rowspan='2'>Tên thành phẩm</th>
					<th rowspan='2'>Tồn đầu kỳ</th>
					<th colspan='<?php echo $this->in_count; ?>'>
						Nhập trong kỳ
					</th>
					<th colspan='<?php echo $this->out_count;?>'>
						Xuất trong kỳ
					</th>
					<th rowspan='2'>Tồn cuối kỳ</th>
				</tr>
				<tr>
					<?php foreach ($this->reasons as $reason){?>
					<th><?php echo $reason->reason_code?></th>
					<?php }?>
				</tr>
			</thead>
			<tbody>
				<?php if(count($this->paginator)>0){$no=1; foreach ($this->paginator as $row){?>
				<tr>
					<?php echo $this->partial('index/manage/order.phtml', 'admin',array($no++)); ?>
					<td >
						<?php echo $row->inbound_detail_product_code?>
					</td>
					<td >
						<?php echo  $row->m_Array['product_name'] ?>
					</td>
					<td class="right">
						<?php $first=$row->m_Array['first'];echo $this->partial('index/format/float.phtml','admin',array($first))?>
					</td>	
					<?php 
					$last=$first;
					foreach ($this->reasons as $reason)
					{
						$quantity=$row->m_Array['reason_'.$reason->reason_code];
						$last=$last+($reason->reason_inbound_type==0?1:-1)*$quantity;
					?>
					<td class="right" style="background-color:<?php echo $reason->reason_inbound_type==0?"#dce6f1":"#ebf1de"?>">
						<?php echo $this->partial('index/format/float.phtml','admin',array($quantity))?>
					</td>
					<?php 
					}
					?>
					<td class="right">
						<?php echo $this->partial('index/format/float.phtml','admin',array($last))?>
					</td>
				</tr>
				<?php }}?>
			</tbody>
			<tfoot>
				<tr>
					<td colspan='100'>
						<div class='container'>
							<?php if($this->paginator) echo $this->paginationControl($this->paginator) ?>
						</div>
					</td>
				</tr>
			</tfoot>
		</table>
	</fieldset>
	</div>
	<!-- / -->
	
</dl>
</form>
